package org.insia.smartposse.struts.action;

import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.insia.smartposse.config.DAOFactory;
import org.insia.smartposse.metier.User;
/**
 * 
 * @author sok hout
 *
 */
public class DashboardAction extends DispatchAction {
	protected final Logger log = Logger.getLogger(getClass());
	
	@Override
	public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	throws Exception {
		
		log.info("Dans: ShowDashboardAction");
		
		if (request.getSession().getAttribute("user") instanceof User) {
			User user = (User) request.getSession().getAttribute("user");
			User u = DAOFactory.getUserDAO().get(user.getId());
			request.getSession().setAttribute("user", u);
			Set<org.insia.smartposse.metier.Project> projectLeader = u.getProjectSet();

			request.setAttribute("projects", projectLeader);
		}
		
		return mapping.findForward("show");
	}
	

	public ActionForward createProject(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 
    throws Exception {
		return mapping.findForward("success");
	}
	
	
} 
	
